{extend name="admin@public/basic" /}
{block name="style"}{/block}
<!-- <link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/> -->

{block name="cotent"}
<link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/>
<style>
    .tip{
        color: red;
    }
    .gray-tip {
        font-family: sans-serif !important;
        font-weight: 10 !important;
        margin-top: 5px !important;
        color: #A8A8A8 !important;
    }
    .layui-table td, .layui-table th {
        padding: 9px 4px;
    }
    .newupload{
        width: 100px !important;
        height: 40px !important;
        background: url(__STATIC__/image/admin/nopic.png) no-repeat;
        background-size: 100% 100%;
        border:none;
        overflow: hidden;
        cursor: pointer;
        position: relative;
        text-align: center;
    }
    .newInput{
        width: 80px !important;
    }
    .webuploader-container input {
        width: 100%;
        height: 100%;
    }

    .webuploader-pick {
        width: 100%;
        height: 100%;
        border: 1px solid blue;
    }
    .thumbBox {
        position: relative;
    }
    .thumbBox input{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        opacity: 0;
        cursor: pointer;
    }
</style>
<form id="form" class="layui-form" style="width:80%;">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基本信息</li>
        </ul>
        <div class="layui-tab-content ">
            <!--基本信息-->
            <div class="layui-tab-item layui-show">
                <input type="hidden" id="app_sn" value="{$app_sn}"/>
                <div class="layui-form-item layui-row layui-col-xs12">
                    <label class="layui-form-label">主板型号</label>
                    <div class="layui-input-block">
                        <select name="model_id" class="model_id" lay-filter="userGrade">
                            {if !empty($mainboard)}
                            {foreach $mainboard as $k => $v}
                            <option value="{$v.mainboard_id}" {if condition="!empty($data) && $data.model_id == $v.mainboard_id"}selected{/if}>{$v.model}</option>
                            {/foreach}
                            {/if}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-row layui-col-xs12">
                    <label class="layui-form-label">主板编号</label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn newBtnPrimary" id="uploadFile"><i
                                class="layui-icon">&#xe67c;</i>选择文件
                        </button>
                        <div class="layui-upload-list"></div>
                    </div>
                </div>
                <input type="hidden" class="file_url" id="file_url" value="" name="file_url">
                <input type="hidden" class="id" name="id" value="{$data.id|default=''}">
            </div>

        </div>
    </div>


    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" id="addUser">确定</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
        </div>
    </div>
    </div>
</form>

{/block}

{block name="script"}
<script type="text/javascript" src="__STATIC__/layuicms/layui/layui.js"></script>
<script type="text/javascript" src="__STATIC__/plugs/webuploader.min.js"></script>

<script>

    layui.use(['form','layer','upload','element'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            upload = layui.upload,
            element = layui.element,
            $ = layui.jquery;

        //一些事件监听
        element.on('tab(demo)', function (data) {
            console.log(data);
        });

        //var api_hosts = "{$api_host}";
        upload.render({
            elem: '#uploadFile',
            data: {
                type: 1,//表示保存原文件名
            },
            exts: '',
            //url: api_hosts + 'Boss/Equipment/imports',
            url:"{:url('api/Upload/uploadFile')}",
            accept:'file', //普通文件,
            auto:true,//是否自动上传
            type:"post",  //此处是为了演示之用，实际使用中请将此删除，默认用post方式提交
            done: function(res, index, upload){
                //parent.layer.close(layerIndex);
                //如果上传失败
                if (res.code <0) {
                    return layer.msg('上传失败', {icon: 2, time: 1000});
                }
                //上传成功
                var html = '';
                html += '<input type="hidden" name="file"  value="' + res.data.url + '">';
                html += '<span>' + res.data.url + '</span>';
                $("#uploadFile").siblings('.layui-upload-list').html(html);
                $("#file_url").val(res.data.url);
            }
        });

        /**
         * 导入功能
         */
        $("#addUser").click(function () {
            var url = '{:url("$thisClass/import")}';
            var file_url = $("#file_url").val();
            var data = {
                model_id: $(".model_id").val(),
                //model_id:$('#model_id option:selected').val(),
                app_sn: $("#app_sn").val(),
                file_url: file_url
            };
            $.ajax({
                url: url,
                method:"POST",
                data: data,
                success:function(res){
                    if(res.code ==1){
                        layer.msg(res.msg,{icon: 1});
                        setTimeout(function(){
                            //刷新父页面
                            parent.location.reload();
                        },500);

                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });

        form.render();

    });


</script>
{/block}
